﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;

namespace sjzd
{
    /// <summary>
    /// WPFChangeQX.xaml 的交互逻辑
    /// </summary>
 

    public partial class WPFChangeQX : Window
    {
        string configpathPath = System.Environment.CurrentDirectory + @"\设置文件\路径设置.txt";
        string configXZPath = System.Environment.CurrentDirectory + @"\设置文件\旗县乡镇.txt";
        public WPFChangeQX()
        {
            InitializeComponent();
            
            Dictionary<int, string> mydic = new Dictionary<int, string>()
            {
                
            };
            int ID = 1;
            StreamReader sr = new StreamReader(configXZPath, Encoding.Default);
            String line;
            line = sr.ReadLine();
            sr.Close();
            string[] linShi1 = line.Split(':');
            int intQXGS = Convert.ToInt16(linShi1[1]),i=0;
            sr = new StreamReader(configXZPath, Encoding.Default);
            while (ID<=intQXGS)
            {
                line = sr.ReadLine();
                if (i%2==1)
                {
                    string[] SZLS = line.Split(',');
                    mydic.Add(ID++,SZLS[0]);
                }
                i++;
            }
            sr.Close();
            QXList.ItemsSource = mydic;
            QXList.SelectedValuePath = "Key";
            QXList.DisplayMemberPath = "Value";
        }

        private void QXList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CStationName.Text = QXList.SelectedItem.ToString();
            int ID = 1;
            int intLS = QXList.SelectedIndex+1;
            StreamReader sr = new StreamReader(configXZPath, Encoding.Default);
            String line;
            line = sr.ReadLine();
            sr.Close();
            string[] linShi1 = line.Split(':');
            int intQXGS = Convert.ToInt16(linShi1[1]), i = 0;
            sr = new StreamReader(configXZPath, Encoding.Default);
            while (ID <= intQXGS)
            {
                line = sr.ReadLine();
                if (i % 2 == 0 && i != 0)
                {
                    if(ID==intLS)
                    {
                        string[] szLS = line.Split(',');
                        stationID.Text = szLS[0];
                        CStationID.Text = stationID.Text;
                        
                        sr.Close();
                        return;
                    }
                    ID++;
                }
                i++;
            }
            sr.Close();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            
            Dictionary<int, string> mydic = new Dictionary<int, string>()
            {

            };
            int ID = 1;
            StreamReader sr = new StreamReader(configXZPath, Encoding.Default);
            String line;
            line = sr.ReadLine();
            sr.Close();
            string[] linShi1 = line.Split(':');
            int intQXGS = Convert.ToInt16(linShi1[1]), i = 0;
            sr = new StreamReader(configXZPath, Encoding.Default);
            while (ID <= intQXGS)
            {
                line = sr.ReadLine();
                if (i % 2 == 0&&i!=0)
                {
                    string[] SZLS = line.Split(',');
                    mydic.Add(ID++, SZLS[0]);
                }
                i++;
            }
            sr.Close();
            QXList.ItemsSource = mydic;
            QXList.SelectedValuePath = "Key";
            QXList.DisplayMemberPath = "Value";
        }
    }
}
